const mysql=require('mysql2')
const db=mysql.createPool({
    host:'127.0.0.1',
    user:'root',
    password:'wl615724',
    database:'mydb01'
})
// db.query('select * from users',(err,result)=>{
//     console.log(result)
// })
//1.插入数据
const userNew1={username:'acc',password:'123',status:1}
// const sqStr='insert into users (username,password,status) values (?,?,?)'
// db.query(sqStr,[userNew.username,userNew.password,userNew.status],(err,result)=>{
//     console.log(result)
// })
// const userNew2={username:'acb',password:'1235'}
// const sqStr='insert into users set ?'
// db.query(sqStr,userNew2,(err,result)=>{
//     console.log(result)
// })
//2.插入数据库
// const userNew3={username:'acn',password:'123c',id:2}
// const sqStr='update users set username=?,password=? where id=?'
// db.query(sqStr,[userNew3.username,userNew3.password,userNew3.id],(err,result)=>{
//     console.log(result);
// })
// const userNew4={username:'acnb',password:'123cb',id:2}
// const sqStr='update users set ? where id=?'
// db.query(sqStr,[userNew4,userNew4.id],(err,result)=>{
//     console.log(result.affectedRows)
// })
//3.删除数据 一般采用标记删除不直接删除数据
// const sqStr='delete from users where id=1'
// db.query(sqStr,(err,result)=>{
//     console.log(result)
// })
// const sqStr='delete from users where id=?'
// db.query(sqStr,2,(err,result)=>{
//     console.log(result)
// })